package com.ydy.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ydy.dao.ShopMapper;
import com.ydy.domain.Product;
import com.ydy.domain.Shop;
import com.ydy.service.ShopService;
@Service
public class ShopServiceImpl implements ShopService{

	@Resource
	private ShopMapper shopMapper;

	@Override
	public PageInfo<Shop> list(Shop s, Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		
		
		
		List<Shop> list = shopMapper.selects(s);
		return new PageInfo<Shop>(list);
	}

	@Override
	public List<Product> getProducts() {
		// TODO Auto-generated method stub
		return shopMapper.getProducts();
	}

	@Override
	public int add(Shop s) {
		//添加商铺表
		int i = shopMapper.addShop(s);
		//添加中间表
		String pnames = s.getPnames();
		String[] split = pnames.split(",");
		int ii = shopMapper.addCenter(s,split);
		
		
		return ii;
	}

	@Override
	public Shop show(String id) {
		// TODO Auto-generated method stub
		return shopMapper.show(id);
	}

	@Override
	public int dels(Integer[] ids) {
		// TODO Auto-generated method stub
		//删除商店表
		shopMapper.dels(ids);
		//删除中间表
		int i = shopMapper.delCenter(ids);
		return i;
	}

	@Override
	public Shop getOneForUpdate(String id) {
		Shop s = shopMapper.getOneForUpdate(id);
		return s;
	}

	@Override
	public int update(Shop s) {
		//修改商店表
		shopMapper.updateShop(s);
		//删除中间表
		String pnames = s.getPnames();
		String[] ids = pnames.split(",");
		shopMapper.delCenterForUpdate(ids,s);
		//添加中间表
		shopMapper.addCenter(s, ids);
		int i=1;
		return i;
	}
}
